import { CoolController, BaseController } from '@cool-midway/core';
import { BizOrderListEntity } from '../../entity/list';
import { BizOrderListService } from '../../service/list';
import { Body, Inject, Post } from '@midwayjs/core';

/**
 * 订单
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: BizOrderListEntity,
  service: BizOrderListService,
  pageQueryOp: {
    fieldEq: ['id', 'userId', 'status'],
    keyWordLikeFields: [],
  },
})
export class BizOrderListAppController extends BaseController {
  @Inject()
  bizOrderListService: BizOrderListService;

  @Post('/placeOrder', {
    summary: '生成订单',
  })
  async placeOrder(
    @Body('userId') userId: number,
    @Body('startDate') startDate: string,
    @Body('endDate') endDate: string,
    @Body('priceDeposit') priceDeposit: number,
    @Body('detail') detail: string
  ) {
    return this.ok(
      await this.bizOrderListService.placeOrder(
        userId,
        startDate,
        endDate,
        priceDeposit,
        detail
      )
    );
  }

  @Post('/activeCancelOrder', {
    summary: '取消订单',
  })
  async activeCancelOrder(
    @Body('orderNo') orderNo: string,
    @Body('notes') notes: string,
    @Body('orderType') orderType: number
  ) {
    return this.ok(
      await this.bizOrderListService.activeCancelOrder(
        orderNo,
        notes,
        orderType
      )
    );
  }

  @Post('/placePayOrder', {
    summary: '生成支付订单',
  })
  async placePayOrder(
    @Body('orderId') orderId: number,
    @Body('userId') userId: number
  ) {
    return this.ok(
      await this.bizOrderListService.placePayOrder(orderId, userId)
    );
  }

  @Post('/activeUpdateTOrderStatus', {
    summary: '查询第三方支付订单状态',
  })
  async activeUpdateTOrderStatus(
    @Body('orderNo') orderNo: string,
    @Body('orderType') orderType: number
  ) {
    return this.ok(
      await this.bizOrderListService.activeUpdateTOrderStatus(
        orderNo,
        orderType
      )
    );
  }

  @Post('/upLoadProof', {
    summary: '上传结算凭证',
  })
  async upLoadProof(
    @Body('orderId') orderId: number,
    @Body('workerId') workerId: number,
    @Body('priceSelfWorkAll') priceSelfWorkAll: number,
    @Body('photo') photo: string,
    @Body('notes') notes: string
  ) {
    return this.ok(
      await this.bizOrderListService.upLoadProof({
        orderId,
        workerId,
        priceSelfWorkAll,
        photo,
        notes,
      })
    );
  }
}
